package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService service;
    @RequestMapping("login")
    public String login(String userName, String pwd, HttpServletRequest request){
        UserBean userBean = service.login(userName, pwd);
        System.out.println(userBean);
        if (userBean != null){
            request.getSession().setAttribute("loginUser",userBean);
            return "ok";
        }
        return "on";
    }
    @RequestMapping("getUserName")
    public String getUserName(HttpServletRequest request){
        UserBean userBean =
                (UserBean)request.getSession().getAttribute("loginUser");
        return userBean.getName();
    }

}
